import { defineStore } from "pinia";
import { ref, computed } from "vue";
export const useStore = defineStore("store", () => {
        const token = ref("");
        const userInfo = ref({})
        const curData = ref([])
        const recent = ref([])
        const setToken = value=>token.value = value;
        const getToken = computed(() => token.value);
        const setUserInfo = value=>userInfo.value = value;
        const getUserInfo = computed(()=>userInfo.value)
        const setCurData = value=>curData.value = value
        const getCurData = computed(()=>curData.value)
        const setRecent = value=>recent.value.push(value)
        const getRecent = computed(()=>recent.value)
        const deleteRecent = (index='All')=> +index+1?recent.value.splice(index,1):recent.value=[]
        const orderInfo = ref({})
        const setOrderInfo = value=>orderInfo.value=value
        const getOrderInfo = computed(()=>orderInfo.value)
        return {
            token,
            setToken,
            getToken,
            userInfo,
            setUserInfo,
            getUserInfo,
            curData,
            setCurData,
            getCurData,
            recent,
            setRecent,
            getRecent,
            deleteRecent,
            orderInfo,
            setOrderInfo,
            getOrderInfo
        };
    },
    {unistorage: true},
);